package com.wlyuan.open.scanner.assembler;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.open.dto.OpenGoodsSyncDTO;
import com.wlyuan.open.scanner.domain.goods.Goods;
import com.wlyuan.open.scanner.utils.mappings.MappingInvalid;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author lijing
 * @description
 */
public class ScannerGoodsAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {MappingInvalid.class, MappingIds.class})
    public interface Assembler {

        /**
         * 转换
         *
         * @param source
         * @return
         */
        @Mappings({
                @Mapping(target = "status", source = "goodsInvalid"),
                @Mapping(target = "createAt", source = "createTime"),
                @Mapping(target = "updateAt", source = "updateTime"),
        })
        OpenGoodsSyncDTO assemble(Goods source);

        /**
         * 转换
         *
         * @param source
         * @return
         */
        List<OpenGoodsSyncDTO> assemble(List<Goods> source);

    }

    public static List<OpenGoodsSyncDTO> assemble(List<Goods> creation) {
        return ASSEMBLER.assemble(creation);
    }

    public static OpenGoodsSyncDTO assemble(Goods creation) {
        return ASSEMBLER.assemble(creation);
    }

}
